<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" ref="elFormRef" label-position="right" :rules="rule" label-width="80px">
        <el-form-item label="首办/大办:" prop="firstOrLarge">
          <el-input v-model="formData.firstOrLarge" :clearable="true"  placeholder="请输入首办/大办" />
       </el-form-item>
        <el-form-item label="配件名称:" prop="accessoryName">
          <el-input v-model="formData.accessoryName" :clearable="true"  placeholder="请输入配件名称" />
       </el-form-item>
        <el-form-item label="材质属性:" prop="materialProperty">
          <el-input v-model="formData.materialProperty" :clearable="true"  placeholder="请输入材质属性" />
       </el-form-item>
        <el-form-item label="工序:" prop="workingProcedure">
          <el-input v-model="formData.workingProcedure" :clearable="true"  placeholder="请输入工序" />
       </el-form-item>
        <el-form-item label="配件编号:" prop="accessoryNum">
          <el-input v-model="formData.accessoryNum" :clearable="true"  placeholder="请输入配件编号" />
       </el-form-item>
        <el-form-item label="使用状态:" prop="usageStatus">
          <el-input v-model="formData.usageStatus" :clearable="true"  placeholder="请输入使用状态" />
       </el-form-item>
        <el-form-item label="物料说明:" prop="materialDesc">
          <el-input v-model="formData.materialDesc" :clearable="true"  placeholder="请输入物料说明" />
       </el-form-item>
        <el-form-item label="单位:" prop="unit">
          <el-input v-model="formData.unit" :clearable="true"  placeholder="请输入单位" />
       </el-form-item>
        <el-form-item label="物料群组说明:" prop="materialGroupDesc">
          <el-input v-model="formData.materialGroupDesc" :clearable="true"  placeholder="请输入物料群组说明" />
       </el-form-item>
        <el-form-item label="是否有模具:" prop="isMoldAvailable">
          <el-input v-model="formData.isMoldAvailable" :clearable="true"  placeholder="请输入是否有模具" />
       </el-form-item>
        <el-form-item label="款式编号:" prop="styleNum">
          <el-input v-model="formData.styleNum" :clearable="true"  placeholder="请输入款式编号" />
       </el-form-item>
        <el-form-item label="是否辨别金胶共用:" prop="isSpleenMetalShare">
          <el-input v-model="formData.isSpleenMetalShare" :clearable="true"  placeholder="请输入是否辨别金胶共用" />
       </el-form-item>
        <el-form-item label="(首办)创建日期:" prop="firstCreateAt">
          <el-date-picker v-model="formData.firstCreateAt" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="已起模配架类型:" prop="moldStartedType">
          <el-input v-model="formData.moldStartedType" :clearable="true"  placeholder="请输入已起模配架类型" />
       </el-form-item>
        <el-form-item label="物料群组:" prop="materialGroup">
          <el-input v-model="formData.materialGroup" :clearable="true"  placeholder="请输入物料群组" />
       </el-form-item>
        <el-form-item label="物料尺码:" prop="materialSize">
          <el-input v-model="formData.materialSize" :clearable="true"  placeholder="请输入物料尺码" />
       </el-form-item>
        <el-form-item label="模具状态:" prop="moldStatus">
          <el-input v-model="formData.moldStatus" :clearable="true"  placeholder="请输入模具状态" />
       </el-form-item>
        <el-form-item label="图纸编号:" prop="drawingNum">
          <el-input v-model="formData.drawingNum" :clearable="true"  placeholder="请输入图纸编号" />
       </el-form-item>
        <el-form-item label="是否外发:" prop="isOutSource">
          <el-input v-model="formData.isOutSource" :clearable="true"  placeholder="请输入是否外发" />
       </el-form-item>
        <el-form-item label="外发需求:" prop="outSourceNeed">
          <el-input v-model="formData.outSourceNeed" :clearable="true"  placeholder="请输入外发需求" />
       </el-form-item>
        <el-form-item label="首办所属款号:" prop="firstOrderNumBelongTo">
          <el-input v-model="formData.firstOrderNumBelongTo" :clearable="true"  placeholder="请输入首办所属款号" />
       </el-form-item>
        <el-form-item label="大办所属款号:" prop="largeScaleNumBelongTo">
          <el-input v-model="formData.largeScaleNumBelongTo" :clearable="true"  placeholder="请输入大办所属款号" />
       </el-form-item>
        <el-form-item label="(首办)配件编号:" prop="firstOrderAccessoryNum">
          <el-input v-model="formData.firstOrderAccessoryNum" :clearable="true"  placeholder="请输入(首办)配件编号" />
       </el-form-item>
        <el-form-item label="(首办)共用主档配件编号:" prop="firstOrderShareDocumentAccessoryNum">
          <el-input v-model="formData.firstOrderShareDocumentAccessoryNum" :clearable="true"  placeholder="请输入(首办)共用主档配件编号" />
       </el-form-item>
        <el-form-item label="(首办)图纸编号:" prop="firstOrderDrawingNum">
          <el-input v-model="formData.firstOrderDrawingNum" :clearable="true"  placeholder="请输入(首办)图纸编号" />
       </el-form-item>
        <el-form-item label="配件编号1:" prop="accessoryNum1">
          <el-input v-model="formData.accessoryNum1" :clearable="true"  placeholder="请输入配件编号1" />
       </el-form-item>
        <el-form-item label="配件编号2:" prop="accessoryNum2">
          <el-input v-model="formData.accessoryNum2" :clearable="true"  placeholder="请输入配件编号2" />
       </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
          <el-button type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import {
  createAccessoryNumberDocument,
  updateAccessoryNumberDocument,
  findAccessoryNumberDocument
} from '@/api/confAccessoryNumberDocument'

defineOptions({
    name: 'AccessoryNumberDocumentForm'
})

// 自动获取字典
import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref, reactive } from 'vue'

const route = useRoute()
const router = useRouter()

const type = ref('')
const formData = ref({
            firstOrLarge: '',
            accessoryName: '',
            materialProperty: '',
            workingProcedure: '',
            accessoryNum: '',
            usageStatus: '',
            materialDesc: '',
            unit: '',
            materialGroupDesc: '',
            isMoldAvailable: '',
            styleNum: '',
            isSpleenMetalShare: '',
            firstCreateAt: new Date(),
            moldStartedType: '',
            materialGroup: '',
            materialSize: '',
            moldStatus: '',
            drawingNum: '',
            isOutSource: '',
            outSourceNeed: '',
            firstOrderNumBelongTo: '',
            largeScaleNumBelongTo: '',
            firstOrderAccessoryNum: '',
            firstOrderShareDocumentAccessoryNum: '',
            firstOrderDrawingNum: '',
            accessoryNum1: '',
            accessoryNum2: '',
        })
// 验证规则
const rule = reactive({
})

const elFormRef = ref()

// 初始化方法
const init = async () => {
 // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (route.query.id) {
      const res = await findAccessoryNumberDocument({ ID: route.query.id })
      if (res.code === 0) {
        formData.value = res.data.reaccessoryNumberDocument
        type.value = 'update'
      }
    } else {
      type.value = 'create'
    }
}

init()
// 保存按钮
const save = async() => {
      elFormRef.value?.validate( async (valid) => {
         if (!valid) return
            let res
           switch (type.value) {
             case 'create':
               res = await createAccessoryNumberDocument(formData.value)
               break
             case 'update':
               res = await updateAccessoryNumberDocument(formData.value)
               break
             default:
               res = await createAccessoryNumberDocument(formData.value)
               break
           }
           if (res.code === 0) {
             ElMessage({
               type: 'success',
               message: '创建/更改成功'
             })
           }
       })
}

// 返回按钮
const back = () => {
    router.go(-1)
}

</script>

<style>
</style>
